<template>
  <a-card :bordered="false" class="card-area">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.ssyxm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh+"-"+ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zy">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="学习形式">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zy">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:16}" :xl="{span:8}">
            <a-button type="primary" @click="loadData">查询</a-button>
              <a-button type="primary" @click="exportExcel">导出</a-button>
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"
      :rowSelection="options.rowSelection"
      :pagination="false"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
  </a-card>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0311', 'TYPE0312', 'TYPE0126', 'TYPE0075', 'TYPE0056', 'TYPE0083', 'TYPE0125', 'TYPE0072']
export default {
  name: 'Recruitstat',
  components: {
    STable
  },
  data () {
    return {
      advanced: true,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        hzfs: 'yx'
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '招生年度',
          dataIndex: 'zsnd'
        },
        {
          title: '院系代码',
          dataIndex: 'yxdm'
        },
        {
          title: '院系',
          dataIndex: 'yx'
        },
        {
          title: '专业代码',
          dataIndex: 'zydm'
        },
        {
          title: '专业',
          dataIndex: 'zy'
        },
        {
          title: '学习形式',
          dataIndex: 'xxxs'
        },
        {
          title: '总计',
          dataIndex: 'zj'
        },
        {
          title: '非专业学位计划',
          dataIndex: 'fzyxwjh'
        },
        {
          title: '专业学位计划',
          dataIndex: 'zyxwjh'
        }
      ],

      // custom table alert & rowSelection
      options: {
        alert: { show: false }
      },
      visible: false,
      confirmLoading: false,
      editId: null,
      selectMenu: {
        yx: [], // 院系
        zy: [] // 所属专业
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    // 选择院系
    yxChange (code) {
    },
    // 选择招生年度
    zsndChange () {
    },
    // 加载数据
    loadData () {
      return new Promise(resolve => { resolve() }).then(res => {
        this.data = [{
          zsnd: '1990',
          yxdm: 'window',
          yx: 'XXXXX',
          zydm: 'document',
          zy: '搞大事',
          zj: '190人',
          zjh: '一个好计划',
          fzyxwjh: '没学位倒霉啊',
          zyxwjh: '家里蹲学位',
          xxxs: '函授',
          key: 1
        }, {
          zsnd: '1990',
          yxdm: 'window',
          yx: 'XXXXX',
          zj: '180人',
          zydm: 'document',
          zy: '搞事',
          zjh: '一个好计划',
          fzyxwjh: '没学位倒霉啊',
          zyxwjh: '家里蹲学位',
          xxxs: '函授',
          key: 2
        }]
      })
    },
    // 导出
    exportExcel () {
      console.log('导出')
    }
  }
}
</script>
